<?php
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => '</h2>',
	));

function browse_happy_template() {
	$getit = __( 'WordPress recommends a better browser' );
	echo '<p><a href="http://browsehappy.com/" title="'.$getit.'"><img src="'.get_bloginfo('home').'/wp-admin/images/browse-happy.gif" alt="Browse Happy" /></a></p>';
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
	add_action('wp_footer','browse_happy_template');

function gravatar_email($email) {
	if (!function_exists('get_avatar') || !empty($email)) {
	$rating = (!get_option('avatar_rating')) ? 'PG' : get_option('avatar_rating');
	$size = 48;
	$default = get_bloginfo('template_directory').'/images/comment-gravatar'.template_color_for_gravatar().'.jpg';
	$out = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($email));
	$out .= "&amp;rating=".$rating;
	$out .="&amp;size=".$size;
	$out .= "&amp;default=".urlencode($default);
	echo '<img src="'.$out.'" class="avatar" id="commentpreview_gravatar" alt="Gravatar" />';
	} else {
	echo get_avatar($email, '48', get_bloginfo('template_directory').'/images/comment-gravatar'.template_color_for_gravatar().'.jpg');
	}
}

function gravatar() {
	global $comment;
	if (!function_exists('get_avatar') || !empty($comment->comment_author_email)) {
	$rating = (!get_option('avatar_rating')) ? 'PG' : get_option('avatar_rating');
	$size = 48;
	$default = get_bloginfo('template_directory').'/images/comment-gravatar'.template_color_for_gravatar().'.jpg';
	$out = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($comment->comment_author_email));
	$out .= "&amp;rating=".$rating;
	$out .="&amp;size=".$size;
	$out .= "&amp;default=".urlencode($default);
	echo '<img src="'.$out.'" class="avatar" alt="Gravatar" />';
	} else {
	echo get_avatar($comment->comment_author_email, '48', get_bloginfo('template_directory').'/images/comment-gravatar'.template_color_for_gravatar().'.jpg');
	}
}

function gravatar_post() {
	if (!function_exists('get_avatar')) {
	$rating = (!get_option('avatar_rating')) ? 'PG' : get_option('avatar_rating');
	$size = 80;
	$default = get_bloginfo('template_directory').'/images/author-gravatar'.template_color_for_gravatar().'.jpg';
	$out = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower(get_the_author_email()));
	$out .= "&amp;rating=".$rating;
	$out .="&amp;size=".$size;
	$out .= "&amp;default=".urlencode($default);
	echo '<img src="'.$out.'" class="avatar" alt="Gravatar" />';
	} else {
	echo get_avatar(get_the_author_email(), '80', get_bloginfo('template_directory').'/images/comment-gravatar'.template_color_for_gravatar().'.jpg');
	}
}

function search_because_of_404() {
	if (!is_404())
		return;
	$home = get_bloginfo('home').'/';
	$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$error404 = str_replace($home,'',$url);
	$searchstring = str_replace(array('/','-',' ','_'),' ',urldecode($error404));
	$searchstring = trim($searchstring);
	$searchstring = $home.'?s='.str_replace(' ','+',$searchstring);
	echo $searchstring;
}

function commentword() {
	$commentwords = array('said','wrote','replied','thought','commented');
	echo $commentwords[rand(0,4)];
}

include(dirname(__FILE__).'/themetoolkit.php');

themetoolkit('modern_blue', array('colorscheme' => 'Color Scheme {checkbox|blue|blue|Blue|pink|pink|Pink|green|green|Green|white|white|White} ## Check off the ones that you would like a possibility of seeing randomly selected.  If you do not select any, the blue option will be used.'), __FILE__);

global $modern_blue;
if (!$modern_blue->is_installed() || !($modern_blue->option['blue'] || $modern_blue->option['pink'] || $modern_blue->option['green'] || $modern_blue->option['white'])) {
	$set_defaults['blue'] = 'blue';
	$result = $modern_blue->store_options($set_defaults);
}
$colorchoices = array();
if ($modern_blue->option['blue'] == 'blue')
	$colorchoices[] = 'blue';
if ($modern_blue->option['pink'] == 'pink')
	$colorchoices[] = 'pink';
if ($modern_blue->option['green'] == 'green')
	$colorchoices[] = 'green';
if ($modern_blue->option['white'] == 'white')
	$colorchoices[] = 'white';
$randomcolortemplate = $colorchoices[rand(0,count($colorchoices)-1)];

function stylesheet_template() {
	global $randomcolortemplate;
	switch ($randomcolortemplate):
	case 'blue':
		bloginfo('stylesheet_url');
		break;
	default:
		echo get_bloginfo('template_directory').'/style-'.$randomcolortemplate.'.css';
	endswitch;
}

function template_color_for_gravatar() {
	global $randomcolortemplate;
	switch ($randomcolortemplate):
	case 'blue':
		return '';
	default:
		return '-'.$randomcolortemplate;
	endswitch;
}

?>
